package com.youlu.campus.admin.course.controller;

import com.alibaba.fastjson.JSON;
import com.youlu.campus.admin.course.dto.CourseVideoOpDTO;
import com.youlu.campus.admin.course.dto.CourseVideoSaveDTO;
import com.youlu.campus.admin.course.dto.CourseVideoSearchDTO;
import com.youlu.campus.admin.course.service.CourseVideoService;
import com.youlu.campus.entity.course.ActivityCourseVideo;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author : [dengbo]
 * @className : CourseVideoController
 * @description : [课程视频控制器，课程视频]
 * @createTime : [2022/5/16 23:03]
 */
@Slf4j
@RestController
public class CourseVideoController {
    @Resource
    private CourseVideoService courseVideoService;

    /**
     * 课程视频列表
     * 课程视频列表
     * @param request 课程视频列表查询请求类
     * @return
     */
    @PostMapping("/course-video/list")
    public QResult list(@Validated @RequestBody CourseVideoSearchDTO request) {
        log.info("CourseVideoController,list,request param:{}", JSON.toJSONString(request));
        Page<ActivityCourseVideo> data = courseVideoService.list(request);
        log.info("ActivityCourseController,list,response:{}", data);
        return QResult.success(data);
    }

    /**
     * 课程视频保存
     * 课程视频保存
     * @param request 课课程视频保存请求类
     * @return
     */
    @PostMapping("/course-video/save")
    public QResult save(@Validated @RequestBody CourseVideoSaveDTO request) {
        log.info("CourseVideoController,save,request param:{}", JSON.toJSONString(request));
        boolean re = courseVideoService.save(request);
        log.info("CourseVideoController,save,response:{}", re);
        return QResult.success(re);
    }

    /**
     * 视频上下架
     * 课程视频上下架操作
     * @param request 视频上下架
     * @return
     */
    @PostMapping("/course-video/operation")
    public QResult operation(@Validated @RequestBody CourseVideoOpDTO request) {
        log.info("CourseVideoController,operation,request param:{}", JSON.toJSONString(request));
        boolean re = courseVideoService.operation(request);
        log.info("CourseVideoController,operation,response:{}", re);
        return QResult.success(re);
    }
}